package com.jixiantubu.wode;

import com.example.jixiantubu.R;
import com.jixiantubu.util.MyApplication;

import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.TextView;

public class Wo_jiebanActivity extends Activity implements OnClickListener {
	TextView wo_faqi, wo_canjia;
	FragmentManager fragmentManager;
	FragmentTransaction fragmentTransaction;
	Bundle bundle;
	String username;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Window window = this.getWindow();
		window.requestFeature(window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_wo_jieban);
		initView();
		init();
	}

	private void initView() {
		wo_faqi = (TextView) findViewById(R.id.wo_faqi);
		wo_canjia = (TextView) findViewById(R.id.wo_canjia);

		wo_faqi.setOnClickListener(this);
		wo_canjia.setOnClickListener(this);
		
		Intent intent=getIntent();
		username=intent.getStringExtra("username");
		Log.e("<>>>>>>>>>>", username);
		if (username.equals(MyApplication.username)) {
			wo_faqi.setText("我发起的");
			wo_canjia.setText("我报名的");
		}else{
			wo_faqi.setText("他发起的");
			wo_canjia.setText("他报名的");
		}
	}
		
		
		
	

	@SuppressLint("NewApi")
	private void init() {
		fragmentManager = getFragmentManager();
		fragmentTransaction = fragmentManager.beginTransaction();
		WocanjiaFragment fragment = new WocanjiaFragment();
		
		 bundle = new Bundle();
		 bundle.putString("username", username);
		 fragment.setArguments(bundle);
		// 替换主布局中的id是container的布局
		fragmentTransaction.replace(R.id.container1, fragment);
		fragmentTransaction.commit();
	}

	@SuppressLint("NewApi")
	@Override
	public void onClick(View v) {
		switch (v.getId()) {

		case R.id.wo_canjia:
			fragmentManager = getFragmentManager();
			fragmentTransaction = fragmentManager.beginTransaction();
			WocanjiaFragment fragment1 = new WocanjiaFragment();
			bundle = new Bundle();
			 bundle.putString("username", username);
			  fragment1.setArguments(bundle);
			
			// 替换主布局中的id是container的布局
			fragmentTransaction.replace(R.id.container1, fragment1);
			fragmentTransaction.commit();
			break;
		case R.id.wo_faqi:
			fragmentManager = getFragmentManager();
			fragmentTransaction = fragmentManager.beginTransaction();
			WodefaqiFragment fragment = new WodefaqiFragment();
			 bundle = new Bundle();
			 bundle.putString("username", username);
			  fragment.setArguments(bundle);
			// 替换主布局中的id是container的布局
			fragmentTransaction.replace(R.id.container1, fragment);
			fragmentTransaction.commit();
			break;
		default:
			break;
		}

	}
}